<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="cake.dao.OrderDetailDao"%>
<%@page import="cake.db.MySqlDb"%>
<%@page import="java.sql.ResultSet"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Shopping Cart page</title>
		<link rel="stylesheet" href="styles/style.css" type="text/css" />
		<script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src="scripts/jquery.select.js" type="text/javascript"></script>
		<script src="scripts/tools.js" type="text/javascript"></script>
		<script src="scripts/script.js" type="text/javascript"></script>
	</head>
	<body>
		<div id="container">
			<div id="header">
				<div id="header_left">
					<img src="images/logo.png" alt="cake"  class="logo"/>
				</div>
				<div style="padding-top: 20px;">
					<input type="text" id="keywords" name="keywords" />
					<input type="image" id="search" src="images/search.jpg" value="search"  onclick="search();"/>
					<span class=" btn" style="margin-left: 50px;"> <%
 	String username = null;
 	long userid = 0;
 	username = (String) session.getAttribute("username");
 	String tempS=(String)session.getAttribute("userid");
 	userid = Long.parseLong(tempS);
 	if (username == null || username.equals("")) {
 		response.sendRedirect("login.jsp");
 	} else {
 %> Welcome: <%=username%> &nbsp;&nbsp;&nbsp;&nbsp; <span
						class="pointer" onclick="toURL('myOrder.jsp')">MyOrders |</span>
						<span class="pointer" onclick="quit();">Quit</span> <%
 	}
 %> </span>
 <span style="margin-left:20px;cursor:pointer;" onclick="toURL('msgBoard.jsp');">MsgBoard</span>
				</div>
				<div id="navigation">
					<ul>
						<li><a href="index.jsp">Home</a> |</li>
						<li><a href="cakes.jsp">Reservation</a> |</li>
						<li><a href="advanced.jsp">Advanced Reservation</a> |</li>
						<li><a href="cakes.jsp?category=5">New Products</a> |</li>
						<%
						if(username==null || username.equals(""))
						{
						%>
						<li><a href="login.jsp">MyOrders</a> |</li>
						<li><a href="login.jsp">Shopping Cart</a> |</li>
						<%
						}
						else
						{
						%>
						<li><a href="myOrder.jsp">MyOrders</a> |</li>
						<li><a href="shoppingCart.jsp">Shopping Cart</a> |</li>
						<%
						}
						%>
						<li><a href="about.jsp">About us</a></li>
					</ul>
				</div>
			</div>
			<div id="content">
				<div style="margin-left: 35px;">
					<div>
						Location：
						<a href="index.jsp">Home</a> &gt; Shopping Carts
					</div>
					<div style="padding: 40px 10px 40px 10px;">
						<div style="text-align:center;">
							Shopping Carts
							<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" bordercolor="#CCCCCC">
								<tr style="background-color:#FCF2E4;">
									<td width="30">
										Index
									</td>
									<td width="200">
										Cake
									</td>
									<td width="130">
										Quantity
									</td>
									<td width="90">
										Amount
									</td>
									<td width="130">
										Operation
									</td>
								</tr>
								<%
									MySqlDb db = new MySqlDb();

									String sql = "select a.*,b.name,b.price,b.picture from shoppingcart a"
										+" left outer join cake b on a.cakeid=b.id where a.userid="+userid;
									
									ResultSet rs=db.query(sql);
									rs = db.query(sql);
									int index = 1;
									while (rs.next()) {
								%>
								<tr>
									<td><%=index%></td>
									<td>
										<img src="<%=rs.getString("picture")%>"
											alt="<%=rs.getString("name")%>"
											style="float: left; width: 50px; height: 50px;" />
										<b>name:</b><%=rs.getString("name")%><br/>
										<b>price:</b><%=rs.getFloat("price")%>
									</td>
									<td>
										<%=rs.getInt("quantity")%> | 
										<input type="button" value="+" class="btn4" onclick="addQ(<%=rs.getLong("id")%>);" />
										<input type="button" value="-" class="btn4" onclick="minusQ(<%=rs.getLong("id")%>);" />
									</td>
									<td><%=rs.getInt("quantity")*rs.getFloat("price")%></td>
									
									<td>
										<input type="button" value="order" class="btn3" onclick="toURL('order.jsp?cart=<%=rs.getLong("id") %>&quantity=<%=rs.getInt("quantity") %>');" />
										<input type="button" value="delete" class="btn3" onclick="deleteCart(<%=rs.getLong("id")%>);" />
									</td>
								</tr>
								<%
									index++;
									}
								%>
							</table>
							<div style="margin-top:10px;margin-left:250px;">
								<%
									if(index>1)
									{
								%>
								<input type="button" value="Order All" class="btn" style="display:none;" onclick="orderAll();" />
								<input type="button" value="Clear" class="btn" onclick="clearCart();" />
								<%
								}
								%>
							</div>
						</div>
					</div>
				</div>
				<div id="categorys">
					<%@include file="footer.jsp" %>
				</div>
			</div>
		</div>
	</body>
</html>
